program list2;

{$APPTYPE CONSOLE}

type
  pelement=^element;
  element=record
    value: integer;
    next: pelement;
  end;

var
  i, n: integer;
  head, h, l: pelement;
  fin: textFile;

procedure per(h: pelement;
n: integer);
var
  tmp: pelement;
begin
  tmp:=h;
  for i:=0 to n-1 do
  begin
    h:=tmp;
    if (n-i>2) then
    begin
      while (h^.next^.next<> nil) do
        h:=h^.next;
      write(h^.value, ' ');
      dispose(h^.next);
      h^.next:=nil;
    end;
  end;
  h:=tmp;
  write(h^.next^.value, ' ');
  write(h^.value);
end;

begin
  assign(fin, 'input.txt');
  reset(fin);
  read(fin, n);
  new(head);
  h:=head;
  l:=h;
  read(fin, head^.value);
  for i:=0 to n-1 do
  begin
    new(head^.next);
    read(fin, head^.next.value);
    head:=head^.next;
  end;
  head^.next:=nil;
  while (l^.next<>nil) do
  begin
    write(l^.value, ' ');
    l:=l^.next;
  end;
  writeln;
  per(h,n);
  readln;
end.

